<?php
require('../include/init.inc.php');
$method = $id = $action = $order_sn = '';
extract($_REQUEST, EXTR_IF_EXISTS);


$order_sns = AdminOrderSn::getAll();
foreach ($order_sns as $sn) {
    $new_order['order_sn'] = $sn['order_sn'];
    $new_order['user_name'] = $sn['user_name'];
    $new_order['phone'] = $sn['phone'];
    $new_order['addr'] = $sn['addr'];
    $new_order['num'] = $sn['num'];
    $new_order['add_date'] = $sn['add_date'];
    $new_order['products_id'] = $sn['product_id'];

    $product = AdminProducts::getProductById($sn['product_id']);
    $new_order['products_name'] = $product['products_name'];
    $kd = AdminKd::getKdInfoBySn($sn['order_sn']);
    $new_order['kd_name'] = $kd['kd_name'];
    if ($kd['isGo'] == 1) {
        $new_order['kd_status'] = '已发货';
    } elseif ($kd['isGo'] == 0) {
        $new_order['kd_status'] = '未发货';
    } else {
        $new_order['kd_status'] = '取消订单';
    }

    $sns[] = $new_order;
}


if ($action == 'del') {
    $sn = AdminOrderSn::getSnBySn($order_sn);

    if (!$sn) {
        Common::exitWithError(ErrorMessage::ORDER_NOT_EXIST, "snap/order_sn.php");
    }

    $where = array('order_sn' => $order_sn);
    $ret = AdminOrderSn::delete($where);
    if ($ret) {
        SysLog::addLog(UserSession::getUserName(), 'Del', 'OrderDel', $id, json_encode($where));
        Common::exitWithSuccess('删除完成', 'snap/order_sn.php');
    } else {
        OSAdmin::alert("error");
    }
}

$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign('osadmin_action_confirm', $confirm_html);
Template::assign('sns', $sns);
Template::display('snap/order_sn.tpl');